<template>
  <div class="article-create">
    <el-card>
      <el-input
        class="title-input"
        :placeholder="$t('msg.article.titlePlaceholder')"
        v-model="title"
        maxlength="20"
        clearable
      ></el-input>
      <el-tabs v-model="activeName">
        <el-tab-pane :label="$t('msg.article.markdown')" name="markdown">
          <Markdown :detail="detail" :title="title" @onSuccess="onSuccess" />
        </el-tab-pane>
        <el-tab-pane :label="$t('msg.article.richText')" name="editor">
          <Editor :title="title" :detail="detail" @onSuccess="onSuccess" />
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import Markdown from './components/Markdown.vue'
import Editor from './components/Editor.vue'
import { useRoute } from 'vue-router'
import { articleDetail } from '@/api/article'
const route = useRoute()
const detail = ref({})
const title = ref('')
const articleId = route.params.id
const getArticleDetail = async () => {
  console.log(123)
  detail.value = await articleDetail(articleId)
  // 标题赋值
  console.log('detail', detail.value)
  title.value = detail.value.title
}
if (articleId) {
  getArticleDetail()
}

const activeName = ref('markdown')
const onSuccess = () => {
  console.log('success...')
  title.value = ''
}
</script>

<style lang="scss" scoped></style>
